/*
 * Copyright (c) 2025 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:hadss_adaptive_layout/hadss_adaptive_layout.dart';

import '../l10n/generated/app_localizations.dart';

class ScrollCloumnWidget extends StatefulWidget {
  final WidthBreakpoint screenType;

  const ScrollCloumnWidget({super.key, required this.screenType});

  @override
  State<ScrollCloumnWidget> createState() => _ScrollCloumnWidgetState();
}

class _ScrollCloumnWidgetState extends State<ScrollCloumnWidget> {
  @override
  Widget build(BuildContext context) {
    return ScrollConfiguration(
        behavior: ScrollConfiguration.of(context).copyWith(
      dragDevices: {
        PointerDeviceKind.touch,
        PointerDeviceKind.mouse,
        PointerDeviceKind.trackpad,
      },
    ),
    child: SingleChildScrollView(
      scrollDirection: Axis.horizontal,
      child: Padding(
        padding: const EdgeInsets.only(top: 10, bottom: 10),
        child: Row(
          children: buildRowColumnWidget(),
        ),
      ),
    ));
  }

  List<Widget> buildRowColumnWidget() {
    AppLocalizations il8n = AppLocalizations.of(context)!;
    List<Widget> items = [];
    List<String> titleList = [
      il8n.comprehensive,
      il8n.single,
      il8n.video,
      il8n.playlist,
      il8n.singer,
      il8n.listening,
      il8n.ring,
      il8n.album,
      il8n.lyric
    ];

    for (var element in titleList) {
      items.add(buildItem(
          title: element,
          bgColor: element == il8n.comprehensive
              ? const Color(0xFFFF1949)
              : const Color(0x0d000000)));
    }

    return items;
  }

  Widget buildItem(
      {String title = "", Color bgColor = const Color(0x0d000000)}) {
    double width = 72;
    if (widget.screenType == WidthBreakpoint.md) {
      width = 88;
    } else if (widget.screenType == WidthBreakpoint.lg ||
        widget.screenType == WidthBreakpoint.xl) {
      width = 128;
    }
    AppLocalizations il8n = AppLocalizations.of(context)!;
    return Container(
      width: width,
      height: 28,
      margin: EdgeInsets.only(left: 15, right: title == il8n.lyric ? 15 : 0),
      decoration: BoxDecoration(
          borderRadius: const BorderRadius.all(Radius.circular(16)),
          color: bgColor),
      child: Center(
        child: Text(
          title,
          style: TextStyle(
            fontSize: 12,
            color: title == il8n.comprehensive
                ? Colors.white
                : const Color(0x99000000),
          ),
        ),
      ),
    );
  }
}
